#include  "rtspSrv.h"


void rtsp_hanling(char * data,int sock){
    char line[GLB_LEN_1024]={'\0'};
    int parase_len=0;
    parase_len += rtsp_getLine(data,line);
    rtspRequest request;
    memset(&request,0,sizeof(request));
    rtsp_getHeader(line,&request.header);
    if(!strcasecmp(request.header.method,"OPTIONS")){
        memset(line,0,sizeof(line));
        parase_len += rtsp_getLine(data+parase_len,line);
    }
}

void rtsp_getHeader(char *line,rtspHeader * header){
    char *r=strtok(line," ");
    int index=0;
    while(r != NULL){
        if(index==0){
            sprintf(header->method,"%s",r);//METHOD
        }else if(index==1){
            sprintf(header->url,"%s",r);//URL
        }else{
            sprintf(header->version,"%s",r);//VERSION
        }   
        index++;
        r=strtok(NULL," ");
    }
    // OPTIONS rtsp://127.0.0.1:1554 RTSP/1.0
    // CSeq: 2
    // User-Agent: LibVLC/3.0.10 (LIVE555 Streaming Media v2018.11.26)
}


int rtsp_getLine(char *src,char *dst){
    char *end = strstr(src,"\r\n");
    snprintf(dst,1+end-src,"%s",src);
}
bool  rtsp_judge(char * data){
    char head[GLB_LEN_1024]={'\0'};
    rtsp_getLine(data,head);
    PRTLOG("head:%s",head);
    if(strstr(head,"rtsp://") != NULL  || strstr(head,"RTSP/") != NULL){
        return true;
    }else{
        return false;
    }
}